package com.hamster.crm.web;

import com.hamster.crm.pojo.Employee;
import com.hamster.crm.pojo.EmployeeScore;

import com.hamster.crm.service.EmployeeScoreService;
import com.hamster.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 员工评分记录 Controller
 * @author Tarry
 * @create 2019/12/21 16:07
 */
@RestController
@RequestMapping("employeeScore")
public class EmployeeScoreController {
    @Autowired
    private EmployeeScoreService employeeScoreService;

    /**
     * 提交员工评定分数[可为多个员工提交评分]
     * @param scoreList
     * @return 状态码 200
     */
    @PostMapping("insert")
    public ResponseEntity<Void> insert(@RequestBody List<EmployeeScore> scoreList){
        employeeScoreService.insert(scoreList);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据id获取当前员工的历史分数列表【获取一个员工的多条评分历史记录 降序】
     * @param id 员工id
     * @return List<EmployeeScore> 评分记录列表
     */
    @GetMapping("list")
    public ResponseEntity<List<EmployeeScore>> list(@RequestParam String id){
        List<EmployeeScore> scoreList = employeeScoreService.list(id);
        return ResponseEntity.ok(scoreList);
    }

    /**
     * 获取一个员工的最新评分 级别 和 评分时间  【列表中展示的内容，针对经理级别，前台单独调用】
     * @param id 员工ID
     * @return 最新的评分级别 和 时间
     */
    @GetMapping("get")
    public ResponseEntity<EmployeeScore> get(@RequestParam String id){
        EmployeeScore score = employeeScoreService.get(id);
        return ResponseEntity.ok(score);
    }



    /**
     * 条件查询员工列表【事业部或服务部】
     * @param pageSize     每页条数
     * @param currentPage  当前页
     * @param name         姓名
     * @param startTime   入职时间开始
     * @param endTime     入职时间终止
     *
     * @param department   部门
     * @return
     */
    @GetMapping("employeeList")
    public ResponseEntity<PageResult<Employee>> employeeList(
            @RequestParam(required=false) Integer pageSize,
            @RequestParam(required=false) Integer currentPage,
            @RequestParam(required = false)String name,
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            @RequestParam(required = false) Date startTime,
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            @RequestParam(required = false) Date endTime,
            @RequestParam(required = false)String department
    ){
        PageResult<Employee> employeeList = employeeScoreService.employeeList(pageSize,currentPage,name,startTime,endTime,department);
        return ResponseEntity.ok(employeeList);
    }

}
